package OPE.OVU.MVU.OVU.PQE.nodeEdit;

import OPE.OEQ.MCQ.OVU.PQE.osgi.NodeOSGI;
import ME.VPC.M.app.App;

/*
 * 个人著作权人, 作者 罗瑶光, 浏阳
 * yaoguangluo@outlook.com, 313699483@qq.com, 2080315360@qq.com,
 * (lyg.tin@gmail.com2018年回国后因国内G网屏蔽不再使用）
 * 15116110525-浏阳德塔软件开发有限公司-创始人-法人-总经理-永久非盈利-
 * 430181198505250014, G24402609, EB0581342
 * 204925063, 389418686, F2406501, 0626136
 * 湖南省 浏阳市 集里街道 神仙坳社区 大塘冲一段路 208号 阳光家园别墅小区 第十栋别墅 第三层
 * */
public class LinkList {
    int index = 0;
    String key;
    public LinkNode first;
    public int sum_of_nude = 0;

    public LinkList() {
    }

    public boolean search(LinkNode linkNode, String key) {
        if (null == linkNode) {
            return false;
        }
        if (linkNode.name.equals(key)) {
            return true;
        }
        while (null != linkNode.next) {
            linkNode = linkNode.next;
            if (linkNode.name.equals(key)) {
                while (null != linkNode.pre) {
                    linkNode = linkNode.pre;
                }
                return true;
            }
        }
        return false;
    }

    public LinkNode addNodeOnlyWithFace(LinkNode linkNode, NodeOSGI nOSGI, App NE) {
        NodeOSGI currentOSGI = nOSGI;
        while (null != currentOSGI && null != currentOSGI.pre) {
            currentOSGI = currentOSGI.pre;
        }
        if (null != linkNode) {
            while (null != currentOSGI) {
                if (currentOSGI._SQ_OSU_MSQ_OSU_AVQ_ASQ_SQ_VPC_PCS.equals(linkNode.name)) {
                    linkNode.thisFace = currentOSGI.currentFace.AOP_MVE_CSI_DUQ(NE);
                    sum_of_nude++;
                    index++;
                    return linkNode;
                }
                currentOSGI = currentOSGI.next;
            }
        }
        index++;
        sum_of_nude++;
        return linkNode;
    }

    public LinkNode addNode(LinkNode linkNode, String treeNodeName
        , int x, int y, NodeOSGI nOSGI, App NE) {
        NodeOSGI currentOSGI = nOSGI;
        while (null != currentOSGI && null != currentOSGI.pre) {
            currentOSGI = currentOSGI.pre;
        }
        if (null == linkNode) {
            while (null != currentOSGI) {
                if (currentOSGI._SQ_OSU_MSQ_OSU_AVQ_ASQ_SQ_VPC_PCS.equals(treeNodeName)) {
                    linkNode = new LinkNode();
                    linkNode.I_Name(treeNodeName, x, y, ++index);
                    linkNode.thisFace = currentOSGI.currentFace.AOP_MVE_CSI_DUQ(NE);
                    linkNode.next = null;
                    linkNode.pre = null;
                    sum_of_nude++;
                    return linkNode;
                }
                currentOSGI = currentOSGI.next;
            }
        }
        while (null != linkNode && null != linkNode.next) {
            linkNode = linkNode.next;
        }
        while (null != currentOSGI) {
            if (currentOSGI._SQ_OSU_MSQ_OSU_AVQ_ASQ_SQ_VPC_PCS.equals(treeNodeName)) {
                //linkNode=new linkNode();
                LinkNode node = new LinkNode();
                node.I_Name(treeNodeName, x, y, ++index);
                node.thisFace = currentOSGI.currentFace.AOP_MVE_CSI_DUQ(NE);
                node.pre = linkNode;
                linkNode.next = node;
                sum_of_nude++;
                return linkNode;
            }
            currentOSGI = currentOSGI.next;
        }
        while (null != linkNode && null != linkNode.pre) {
            linkNode = linkNode.pre;
        }
        sum_of_nude++;
        return linkNode;
    }

    public LinkNode deletNode(LinkNode linkNode, String name, int ID, String primaryKey) {
        if (null != linkNode) {
            if (linkNode.name.equals(name) && linkNode.ID == ID
                && linkNode.primaryKey.equalsIgnoreCase(primaryKey)) {
                if (null != linkNode.next) {
                    linkNode = linkNode.next;
                    linkNode.pre = null;
                    return linkNode;
                }
                if (null == linkNode.next) {
                    linkNode = null;
                    return linkNode;
                }
            }
            while (null != linkNode.next) {
                linkNode = linkNode.next;
                if (linkNode.name.equals(name) && linkNode.ID == ID
                    && linkNode.primaryKey.equalsIgnoreCase(primaryKey)) {
                    if (null != linkNode.next) {
                        @SuppressWarnings("unused")
                        LinkNode node = linkNode;
                        linkNode = linkNode.next;
                        linkNode.pre = linkNode.pre.pre;
                        linkNode.pre.next = linkNode;
                        node = null;
                        linkNode = Sort.sort(linkNode);
                        return linkNode;
                    }
                    if (null == linkNode.next) {
                        linkNode = linkNode.pre;
                        linkNode.next = null;
                        linkNode = Sort.sort(linkNode);
                        return linkNode;
                    }
                }
            }
        }
        return linkNode;
    }
}
